package chapter05;

public class Test06_throw1 {
    public static void main(String[] args) {
        setAge(10);
        setAge(-20);
    }
    //抛出的时运行时异常 不用手动的抛出
    static void setAge(int age) throws RuntimeException{
        if(age<0){
            //直接手动抛出异常
            throw new RuntimeException("年龄不能为负数");
        }else{
            System.out.println("年龄为："+age);
        }
    }
}
